package com.example.administrator.stargo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.example.administrator.stargo.R;
import com.example.administrator.stargo.api.HttpCallBack;
import com.example.administrator.stargo.fragment.FindFragment;
import com.example.administrator.stargo.fragment.HomeFragment;
import com.example.administrator.stargo.fragment.MomentsFragment;
import com.example.administrator.stargo.fragment.PersonFragment;
import com.example.administrator.stargo.view.StatusBarUtil;
import com.startsmake.mainnavigatetabbar.widget.MainNavigateTabBar;

public class MainActivity extends AppCompatActivity implements HttpCallBack{

    MainNavigateTabBar navigateTabBar;

    ImageView tab_post_icon;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.colorAccent));
        navigateTabBar = (MainNavigateTabBar) findViewById(R.id.navigateTabBar);
        tab_post_icon = (ImageView) findViewById(R.id.tab_post_icon);

        //对应xml中的containerId
        navigateTabBar.setFrameLayoutId(R.id.main_container);
        //对应xml中的navigateTabTextColor
        navigateTabBar.setTabTextColor(getResources().getColor(R.color.tab_text_normal));
        //对应xml中的navigateTabSelectedTextColor
        navigateTabBar.setSelectedTabTextColor(getResources().getColor(R.color.colorPrimary));

        //恢复选项状态
        navigateTabBar.onRestoreInstanceState(savedInstanceState);
        navigateTabBar.addTab(HomeFragment.class, new MainNavigateTabBar.TabParam(R.mipmap.ic_tab_bar_home, R.mipmap.ic_tab_bar_mine_selected, "精选新闻"));
        navigateTabBar.addTab(MomentsFragment.class, new MainNavigateTabBar.TabParam(R.mipmap.ic_tab_bar_moments, R.mipmap.ic_tab_bar_moments_selected, "其他赛事"));
        navigateTabBar.addTab(PersonFragment.class, new MainNavigateTabBar.TabParam(R.mipmap.ic_tab_bar_find, R.mipmap.ic_tab_bar_find, " "));
        navigateTabBar.addTab(FindFragment.class, new MainNavigateTabBar.TabParam(R.mipmap.ic_tab_bar_find, R.mipmap.ic_tab_bar_find_selected, "竞猜"));
        navigateTabBar.addTab(PersonFragment.class, new MainNavigateTabBar.TabParam(R.mipmap.ic_tab_bar_person, R.mipmap.ic_tab_bar_person_selected, "GO物"));

        navigateTabBar.setTabSelectListener(new MainNavigateTabBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(MainNavigateTabBar.ViewHolder holder) {
                if(holder.tabIndex != 2){
                    tab_post_icon.setBackgroundDrawable(MainActivity.this.getResources().getDrawable(R.mipmap.ic_tab_bar_home_seleced));
                }
            }
        });
        tab_post_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tab_post_icon.setBackgroundDrawable(MainActivity.this.getResources().getDrawable(R.mipmap.tabbar_matching));

                navigateTabBar.setCurrentSelectedTab(2);
            }
        });
    }

    @Override
    public void onSuccess(int action, String res) {

    }

    @Override
    public void showLoadingDialog() {

    }

    @Override
    public void showErrorMessage(String s) {

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //保存当前选中的选项状态
        navigateTabBar.onSaveInstanceState(outState);
    }

}